package com.Bride.smarthome.service.Device;

import com.Bride.smarthome.dao.dto.SmartDeviceDO;
import com.Bride.smarthome.dao.mysql.Smart.SmartDeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
  2025/9/8
  设备控制服务实现类
  com.Bride.smarthome.service.Device
  @author winkin
*/

@Service
public class DeviceControlServiceImpl implements DeviceControlService {

    @Autowired
    private SmartDeviceMapper deviceMapper;

    @Override
    public boolean turnOn(Long deviceId) {
        SmartDeviceDO device = deviceMapper.selectById(deviceId);
        if (device != null) {
            device.setStatus("ON");
            return deviceMapper.updateById(device) > 0;
        }
        return false;
    }

    @Override
    public boolean turnOff(Long deviceId) {
        SmartDeviceDO device = deviceMapper.selectById(deviceId);
        if (device != null) {
            device.setStatus("OFF");
            return deviceMapper.updateById(device) > 0;
        }
        return false;
    }

    @Override
    public boolean setStatus(Long deviceId, String status) {
        SmartDeviceDO device = deviceMapper.selectById(deviceId);
        if (device != null) {
            device.setStatus(status);
            return deviceMapper.updateById(device) > 0;
        }
        return false;
    }
}